package servlets;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modele.Session;
import dao.SessionDAO;

/**
 * Servlet implementation class SessionsOuvertes
 */
public class SessionsFutures extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SessionsFutures() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher vue = getServletContext().getRequestDispatcher(
				"/WEB-INF/sessions.jsp");

		SessionDAO dao;
		try {
			dao = new SessionDAO();
			java.sql.Date now = new java.sql.Date(System.currentTimeMillis());
			List<Session> sessions = dao.listerSessionsFutures(now, 0);
			request.setAttribute("sessions", sessions);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Liste des sessions F :");
			e.printStackTrace();
			request.setAttribute("msg", e.getMessage());
			vue = getServletContext().getRequestDispatcher("/WEB-INF/msg.jsp");
		}
		vue.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
